package com.changgou.search.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.search.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/search/skuInfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 导入sku数据到es
     *
     * @return
     */
    @RequestMapping("/import")
    public Result importData() {

        skuInfoService.importSkuInfoToEs();

        return new Result(true, StatusCode.OK, "导入数据成功！");

    }


    @GetMapping
    public Map search(@RequestParam(required = false) Map<String, String> searchMap) {

        Map<String, Object> dataMap = skuInfoService.search(searchMap);

        return dataMap;

    }


}
